//
//  testViewController.m
//  11
//
//  Created by iD Student on 7/9/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "testViewController.h"

@interface testViewController ()

@end

@implementation testViewController
@synthesize answer;


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setAnswer:nil];
     [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}


-(IBAction)getNumber:(id)sender
{
if(operation)
{   
    if (flag) {
        secondNumber;
    }else {
        secondNumber=secondNumber*10+(float)[sender tag];
    }
    answer.text=[NSString stringWithFormat:@"%3.2f",secondNumber];
    operation= FALSE;
    
    
}
else
{
    if (flag) {
        firstNumber;
    }
    else {
        
    firstNumber=firstNumber*10+(float)[sender tag];
    }
    answer.text= [NSString stringWithFormat:@"%3.2f",firstNumber];
    
}
}

-(IBAction)doMath:(id)sender
{
    switch (operation2) {
        case 0:
            answer.text= [NSString stringWithFormat:@"%3.2f",(firstNumber+secondNumber)];
            break;
            case 1:
            answer.text= [NSString stringWithFormat:@"%3.2f",(firstNumber-secondNumber)];
            break;
            case 2:
            answer.text= [NSString stringWithFormat:@"%3.2f",(firstNumber*secondNumber)];
            break;
            case 3:
            answer.text= [NSString stringWithFormat:@"%3.2f",(firstNumber/secondNumber)];
            break;
            case 4:
            answer.text= [NSString stringWithFormat:@"%3.2f", (pow(firstNumber,secondNumber))];
            break;
            case 5:
            answer.text= [NSString stringWithFormat:@"3.2f", (sqrt(firstNumber))];
            break;
                        
    }
}

-(IBAction)getOperation:(id)sender
{
    operation2=[sender tag];
    answer.text= [NSString stringWithFormat:@""];
    operation= TRUE;
}
-(IBAction)cancelOperation:(id)sender {
firstNumber = 0;
secondNumber= 0;
answer.text = @"0.00";
operation = 0;
}

- (IBAction)decimal:(id)sender {
    flag=TRUE;
    counter=1;
}
@end
